<template>
	<view class="country_info">
		<template v-for="(v, k) in countryList">
			<template v-if="!is_open && k < 6">
				<view class="country_item" :key="k" @tap.stop="selectCountry(k)" >
					<image :src='v.thumb' mode="aspectFill"></image>
					<text :class="countryIndex == k ? 'active_text' : ''">{{v.name}}({{v.nums}})</text>
				</view>
			</template>
			<template v-else>
				<view class="country_item" :key="k" @tap.stop="selectCountry(k)" >
					<image :src='v.thumb' mode="aspectFill"></image>
					<text :class="countryIndex == k ? 'active_text' : ''">{{v.name}}({{v.nums}})</text>
				</view>
			</template>
		</template>
		
		<view class="country_stauts" v-if="countryList.length > 6 && !is_open" @tap.stop="openCountry">
			<text>打开</text>
			<u-icon name="arrow-up" size="20"></u-icon>
		</view>
		<view class="country_stauts" v-if="countryList.length > 6 && is_open" @tap.stop="openCountry">
			<text>收起</text>
			<u-icon name="arrow-down" size="20"></u-icon>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				countryList: [],
				countryIndex: "-1",
				is_open: false,
			}
		},
		created() {
			this.getCountry();
		},
		methods: {
			openCountry() {
				this.is_open = !this.is_open;
			},
			// 国家列表  post64799f7bbb232
			getCountry() {
				this.$api.post(global.apiUrls.post64799f7bbb232, {
					
				}).then(res => {
					// console.log('国家列表', res);
					if (res.data.code == 1) {
						this.countryList = res.data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			selectCountry(index) {
				this.countryIndex = index;
				let data = {
					name: this.countryList[index].name,
					id:this.countryList[index].id
				}
				this.$emit('select', data);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.country_info {
		padding: 0 32rpx;
		display: flex;
		flex-wrap: wrap;
	
		.country_item {
			width: 33%;
			display: flex;
			align-items: center;
			padding: 0 10rpx;
			font-size: 24rpx;
			margin: 16rpx 0;
	
			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 10rpx;
				border-radius: 50%;
			}
			.active_text {
				color: #8B060D;
				font-weight: 600;
			}
		}
	
		.country_stauts {
			width: 33%;
			display: flex;
			align-items: center;
			justify-items: flex-end;
			font-size: 24rpx;
			margin: 16rpx 0;
			padding: 0 10rpx;
	
			text {
				margin-right: 8rpx;
			}
		}
	}
</style>